package com.hongshan.wallet.core.login

import android.arch.lifecycle.ViewModelProviders
import android.databinding.Observable
import android.databinding.ObservableField
import android.databinding.ViewDataBinding
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.hongshan.wallet.BR
import com.hongshan.wallet.R
import com.hongshan.wallet.base.MyActivity
import com.hongshan.wallet.router.RouterIndex
import com.jaeger.library.StatusBarUtil
import kotlinx.android.synthetic.main.activity_login.*

/**
 * Copyright Qiandai Ltd.
 * Copyright (c) 2019
 * All rights reserved
 *
 * @project  : Wallet
 * @package  : com.example.wallet.core.register
 * @author   : Administrator
 * @data     : 2019/3/18
 * @email    : zhangxx@baihang-china.com
 */
@Route(path = RouterIndex.REGISTER)
class RegisterActivity : MyActivity<ViewDataBinding, RegisterViewModel>() {

    val loginVm by lazy { ViewModelProviders.of(this).get(RegisterViewModel::class.java) }

    override fun initVariableId() = BR.registerVm

    override fun initContentView(savedInstanceState: Bundle?) = R.layout.activity_register

    override fun initViewModel() = loginVm

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        StatusBarUtil.setColor(this, resources.getColor(R.color.transparent_white))
        loginVm.sendStatus.addOnPropertyChangedCallback(object : Observable.OnPropertyChangedCallback() {
            override fun onPropertyChanged(sender: Observable, propertyId: Int) {
                val result = (sender as ObservableField<Boolean>).get()!!
                tvSend.isEnabled = result
                flSend.setBackgroundColor(if (result) resources.getColor(R.color.colorAccent) else resources.getColor(R.color.lineGray))
            }
        })
    }
}